#include "log.h"

#include <glog/logging.h>
#include <memory>
#include <sstream>
#include <stdexcept>


namespace log
{
    Logger::Logger(){
        google::InitGoogleLogging("DataCaptutr");
        FLAGS_logtostderr = 1;  // 默认输出到标准错误
        this->setLogLevel(log::LogLevel::Info);
    }

    Logger::~Logger(){
        google::ShutdownGoogleLogging();
    }

    std::shared_ptr<Logger> Logger::getInstance(){
        if (!this->_instance) {
            this->_instance = std::shared_ptr<Logger>(new Logger());
        }
        return this->_instance;
    }
    
    void Logger::setLogLevel(LogLevel level) {
        switch (level) {
            case LogLevel::Fatal:
                FLAGS_minloglevel = 3;
                break;
            case LogLevel::Error:
                FLAGS_minloglevel = 2;
                break;
            case LogLevel::Warning:
                FLAGS_minloglevel = 1;
                break;
            case LogLevel::Info:
                FLAGS_minloglevel = 0;
                break;
            case LogLevel::Debug:
            case LogLevel::Trace:
                FLAGS_minloglevel = 0;  // Glog 默认没有 Trace，使用 INFO 替代
                break;
        }
    }



} // namespace log







